package com.example.lpcommon.thread.lock;

/**
 * Author by lp,on 2020/10/21/021,16:00.
 */
public class TestLock {


    public static void main(String[] args) {
        Task task = new Task();
        Thread t2 = new Thread(new SubThread(task));
        Thread t4 = new Thread(new SubThread(task));
        Thread t5 = new Thread(new SubThread(task));
        new Thread(new SubThread(task)).start();
        new Thread(new SubThread(task)).start();


        Thread t1 = new Thread(new AddThread(task));
        Thread t3 = new Thread(new AddThread(task));
        Thread t7 = new Thread(new AddThread(task));
//        new Thread(new AddThread(task)).start();
//        new Thread(new AddThread(task)).start();
//        new Thread(new AddThread(task)).start();
//        new Thread(new AddThread(task)).start();



        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        t7.start();
    }

}

class AddThread implements Runnable {

    private Task task;

    public AddThread(Task task) {
        this.task = task;
    }

    @Override
    public void run() {
        task.add();
    }

}

class SubThread implements Runnable {

    private Task task;

    public SubThread(Task task) {
        this.task = task;
    }

    @Override
    public void run() {
        task.sub();
    }

}